const connection = require("../app/database");
const { to } = require("../utils");

class ExistsService {
    async resourceExists(tableName, tableId) {
        const statement = `SELECT * FROM ${tableName} WHERE id = ?`;
        const [error, resp] = await to(connection.execute(statement, [tableId]));
        if (error) {
            return error;
        }
        const [result] = resp;
        return result.length > 0;
    }
}

module.exports = new ExistsService();
